﻿using System;
using System.Linq;
using System.Linq.Expressions;

namespace ZSZ.Application
{
    /// <summary>
    /// 仓储接口
    /// </summary>
    /// <typeparam name="T">实体模型</typeparam>
    public interface IRepository<T> where T:class 
    {
        #region 单模型 CRUD 操作
        /// <summary>
        /// 插入一条记录
        /// </summary>
        /// <param name="entity">实体模型</param>
        void Insert(T entity);

        /// <summary>
        /// 更新一条记录
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        void Update(T entity);

        /// <summary>
        /// 增加或更新一条记录
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <param name="isAdd">是否增加</param>
        /// <returns></returns>
        void SaveOrUpdate(T entity, bool isAdd);

        /// <summary>
        /// 通过Lamda表达式获取实体
        /// </summary>
        /// <param name="predicate">Lamda表达式（p=>p.Id==Id）</param>
        /// <returns></returns>
        T Get(Expression<Func<T, bool>> predicate);

        /// <summary>
        /// 通过id获取实体
        /// </summary>
        /// <param name="id">实体id</param>
        /// <returns></returns>
        T GetOneById(long id);

        /// <summary>
        /// 获取所有实体  非删除
        /// </summary>
        /// <returns></returns>
        IQueryable<T> GetAllDataEntity();

        /// <summary>
        /// 删除一条记录
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        void Delete(T entity);

        /// <summary>
        /// 通过实体id删除一条记录
        /// </summary>
        /// <param name="id"></param>
        void DeleteById(long id);

        #endregion
    }
}